package com.networklib.http.impl.get;

import com.networklib.http.exception.NetException;

import java.util.Map;
import java.util.Set;

public class SimpleGetHttpRequestImpl extends GetHttpRequestImpl {
    private final Map params;

    public SimpleGetHttpRequestImpl(String url, Map params) throws NetException {
        super(url);
        this.params = params;
    }

    @Override
    protected String getParams() {
        if (params != null) {
            StringBuilder stringBuilder = new StringBuilder();
            Set entries = params.entrySet();
            for (Object entry : entries) {
                if (stringBuilder.length() > 0) {
                    stringBuilder.append("&");
                }
                stringBuilder.append(((Map.Entry) entry).getKey()).append("=").append(((Map.Entry) entry).getValue());
            }
            return stringBuilder.toString();
        }
        return null;
    }
}
